<template>
    <div class="help-page">
        <img alt="北京华锐云空间" class="bg" :src="`${_oss_}images/help/bg.jpg`" />

        <div class="main">
            <div class="tips">简单几步，快速了解编辑器的能力</div>
            <div class="help-container">
                <div class="help-nav">
                    <div class="help-nav__item" v-for="(item, index) in navList" :class="{
                        collapse: collapse.includes(item.name),
                    }" :key="item.name">
                        <div class="help-nav__cell" @click="onNavCellClick(index)" :class="{ active: isActive(index) }">
                            {{ item.name }}
                            <el-icon color="#333" size="14px" v-if="item.children && item.children.length">
                                <ArrowDown />
                            </el-icon>
                        </div>

                        <div class="help-nav__sub" :class="{
                            active: isActive(index),
                        }">
                            <div class="help-nav__sub-item" v-for="(childItem, childIndex) in item.children"
                                :key="childItem.name" :class="{ active: isActive(index, childIndex) }"
                                @click.stop="onNavCellClick(index, childIndex)">
                                {{ childItem.name }}
                            </div>
                        </div>
                    </div>
                </div>
                <transition name="el-fade-in" mode="out-in">
                    <div class="help-content" :key="navItem.id">
                        <div class="help-content__title">
                            {{ navItem.name }}
                        </div>

                        <div class="help-content__box">
                            <template v-if="navItem.type == 'image'">
                                <div class="help-content__tips" v-html="navItem.tips"></div>
                                <div class="preview-image">
                                    <ImagePreviewP :src="_oss_ +
                                        'images/help/' +
                                        navItem.id +
                                        '.jpg' +
                                        '?x-oss-process=image/watermark,image_' +
                                        toBase64(
                                            'water/logo_white.png?x-oss-process=image/resize,P_30'
                                        ) +
                                        ',g_center,t_50'
                                        " />
                                </div>
                            </template>

                            <template v-else-if="navItem.type == 'video'">
                                <div class="video-list">
                                    <div class="video-item">
                                        <div class="poster-box">
                                            <VideoPreviewP src="https://media.w3.org/2010/05/sintel/trailer.mp4" />
                                        </div>
                                        <div class="video-info">
                                            <div class="video-name">
                                                视频名称
                                            </div>
                                            <div class="video-desc">
                                                视频简介视频简介视频简介视频简介
                                            </div>
                                        </div>
                                    </div>
                                    <div class="video-item">
                                        <div class="poster-box">
                                            <VideoPreviewP src="https://media.w3.org/2010/05/sintel/trailer.mp4" />
                                        </div>
                                        <div class="video-info">
                                            <div class="video-name">
                                                视频名称
                                            </div>
                                            <div class="video-desc">
                                                视频简介视频简介视频简介视频简介
                                            </div>
                                        </div>
                                    </div>
                                    <div class="video-item">
                                        <div class="poster-box">
                                            <VideoPreviewP src="https://media.w3.org/2010/05/sintel/trailer.mp4" />
                                        </div>
                                        <div class="video-info">
                                            <div class="video-name">
                                                视频名称
                                            </div>
                                            <div class="video-desc">
                                                视频简介视频简介视频简介视频简介
                                            </div>
                                        </div>
                                    </div>
                                    <div class="video-item">
                                        <div class="poster-box">
                                            <VideoPreviewP src="https://media.w3.org/2010/05/sintel/trailer.mp4" />
                                        </div>
                                        <div class="video-info">
                                            <div class="video-name">
                                                视频名称
                                            </div>
                                            <div class="video-desc">
                                                视频简介视频简介视频简介视频简介
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </template>

                            <template v-else-if="navItem.type == 'collapse'">
                                <div class="collapse-list">
                                    <div class="collapse-item">
                                        <div class="collapse-title">
                                            PICO Neo3手柄如何操作?
                                            一个视频让你轻松掌控你的VR世界
                                        </div>
                                        <el-icon color="#999" size="18px">
                                            <ArrowDown />
                                        </el-icon>
                                    </div>
                                    <div class="collapse-item">
                                        <div class="collapse-title">
                                            PICO Neo3如何进行投屏?
                                            快来分享一下你的VR世界吧
                                        </div>
                                        <el-icon color="#999" size="18px">
                                            <ArrowDown />
                                        </el-icon>
                                    </div>
                                    <div class="collapse-item">
                                        <div class="collapse-title">
                                            PICO Neo3手柄如何操作?
                                            一个视频让你轻松掌控你的VR世界
                                        </div>
                                        <el-icon color="#999" size="18px">
                                            <ArrowDown />
                                        </el-icon>
                                    </div>
                                    <div class="collapse-item">
                                        <div class="collapse-title">
                                            PICO Neo3如何进行投屏?
                                            快来分享一下你的VR世界吧
                                        </div>
                                        <el-icon color="#999" size="18px">
                                            <ArrowDown />
                                        </el-icon>
                                    </div>
                                </div>
                            </template>
                        </div>
                    </div>
                </transition>
            </div>
        </div>
    </div>
</template>
<script setup>
import { ArrowDown } from "@element-plus/icons-vue";
import { HelpList, useContent } from ".";

const navActive = ref("0");
const collapse = ref([]);

useContent();

const navItem = computed(() => {
    let active = navActive.value.split("-");
    if (active.length === 1) {
        return navList.value[active[0]];
    } else {
        return navList.value[active[0]].children[active[1]];
    }
});
const navList = ref(HelpList);

const isActive = (index, childIndex) => {
    const active = navActive.value.split("-");
    if (childIndex !== undefined) {
        return active[0] == index && active[1] == childIndex;
    } else {
        return active[0] == index;
    }
};

const onNavCellClick = (index, childIndex) => {
    let children = navList.value[index].children;
    if (children && children.length) {
        if (childIndex !== undefined) {
            navActive.value = `${index}-${childIndex}`;
        } else {
            // 手风琴模式
            if (collapse.value[0] === navList.value[index].name) {
                collapse.value = [];
            } else {
                collapse.value = [navList.value[index].name];
            }
        }
    } else {
        navActive.value = index + "";
    }
};
</script>
<style>
.help-bold {
    position: relative;
    color: #ffaa3a;
    font-weight: bold;

    &::after {
        content: "";
        width: 100%;
        height: 1px;
        background-color: #ffaa3a;
        position: absolute;
        bottom: 0px;
        left: 0;
    }
}
</style>
<style lang="scss" scoped>
.help-page {
    position: relative;
    background-color: #edf5fa;
    padding-bottom: 52px;

    .bg {
        width: 100%;
    }

    .main {
        position: relative;
        z-index: 9;
        margin-top: -20vw;
    }

    .tips {
        color: #333333;
        font-size: 20px;
        text-align: center;
    }

    .help-container {
        width: 1200px;
        height: 700px;
        background-color: #fff;
        border-radius: 10px;
        // transform: translateX(-50%);
        margin: 77px auto 0;
        padding-top: 14px;
        display: flex;

        .help-nav {
            width: 246px;
            height: 100%;
            padding: 15px 19px 15px 17px;
            border-right: 1px solid #f1f1f1;
            flex-shrink: 0;
            overflow: auto;

            &__item {
                font-size: 16px;
                line-height: 44px;
                border-radius: 4px;
                font-weight: 400;
                user-select: none;

                &.collapse {
                    .help-nav__sub {
                        display: block;
                    }

                    .help-nav__cell .el-icon {
                        transform: rotate(180deg);
                    }
                }
            }

            &__cell {
                display: flex;
                align-items: center;
                padding-left: 33px;
                cursor: pointer;

                &.active {
                    color: #333;
                    background-color: #f5f5f5;
                    font-weight: 500;
                }

                .el-icon {
                    margin-left: auto;
                    margin-right: 20px;
                    transition: all 0.2s;
                }
            }

            &__sub {
                padding-top: 7px;
                display: none;
                overflow: hidden;

                &-item {
                    line-height: 36px;
                    padding-left: 33px;
                    font-weight: 400;
                    cursor: pointer;
                    overflow: hidden;

                    &.active {
                        background-color: #f5f5f5;
                        border-radius: 4px;
                    }
                }
            }
        }

        .help-content {
            padding: 22px 58px 0 40px;
            overflow: auto;

            &__title {
                display: inline-block;
                position: relative;
                font-size: 32px;

                &::before,
                &::after {
                    content: "";
                    position: absolute;
                    left: 0;
                    width: 100%;
                    background-color: #5085fb;
                }

                &::before {
                    height: 1px;
                    bottom: -14px;
                }

                &::after {
                    height: 3px;
                    bottom: -19px;
                }
            }

            &__tips {
                font-size: 16px;
                margin-top: 64px;
                line-height: 24px;
            }

            .preview-image {
                width: 100%;
                margin-top: 31px;

                img {
                    width: 100%;
                }
            }
        }
    }

    .video-list {
        margin-top: 50px;
        display: flex;
        flex-wrap: wrap;

        .video-item {
            width: 380px;
            padding: 10px 10px 0 10px;
            background: #fff;
            box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.1);
            border-radius: 10px;
            margin-right: 25px;
            margin-bottom: 25px;

            .poster-box {
                position: relative;
                width: 360px;
                height: 190px;
                cursor: pointer;

                .poster-img {
                    width: 100%;
                    height: 100%;
                }

                .play-img {
                    position: absolute;
                    top: 50%;
                    left: 50%;
                    transform: translate(-50%, -50%);
                }
            }

            .video-info {
                padding: 12px 6px 14px;

                .video-name {
                    color: #111;
                    font-size: 18px;
                }

                .video-desc {
                    font-size: 14px;
                    color: #666;
                    margin-top: 13px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                }
            }
        }
    }

    .collapse-list {
        margin-top: 59px;

        .collapse-item {
            display: flex;
            align-items: center;
            width: 854px;
            height: 60px;
            padding: 0 37px 0 27px;
            font-size: 18px;
            background-color: #f5f5f5;
            color: #555;
            margin-bottom: 22px;
            border-radius: 10px;

            .el-icon {
                margin-left: auto;
            }
        }
    }
}
</style>
